const sessionStorage = window.sessionStorage
const JSON = window.JSON
/**
 * @summary 获取session
 * @param {*} name 
 */
export function getSession(name) {
    let value = sessionStorage.getItem(name)
    try {
        value = JSON.parse(value)
        return value
    } catch (error) {
        return value
    }
}
/**
 * @summary 设置session
 * @param {*} name 
 * @param {*} value 
 */
export function setSession(name, value) {
    if (typeof value === 'object') value = JSON.stringify(value)
    return sessionStorage.setItem(name, value)
}
/**
 * @summary 移除某一个session
 * @param {*} name 
 */
export function removeSession(name) {
    return sessionStorage.removeItem(name)
}
/**
 * @summary 清除全部session
 */
export function clearSession() {
    sessionStorage.clear()
}
/**
 * @summary 字符串截取
 * @param {*} str 
 * @param {*} strLength 
 */
export function subStringFn(str, strLength) {
    if (typeof str === 'string') {
        if (strLength >= str.length) return str.slice(0, strLength) + '...'
        return str.slice(0, strLength)
    }
    throw new Error(`${str} 不是字符串！`)
}
/**
 * @summary yyyy-MM-dd 转时间戳
 * @param {*} str 
 */
export function formatTime(str) {
    return Number((new Date(str.replace(/[-\\/]/g, '/'))).getTime())
}
/**
 * @summary 天转时间戳
 * @param {*} str 
 */
export function formatDay(str) {
    if (Number(str)) {
        return Number(str * 24 * 60 * 60 * 1000)
    }
}
/**
 * @summary 时间戳转yyyy-MM-dd
 * @param {*} str 
 */
export function formatYMD(str) {
    var date = new Date(str)// 时间戳为10位需*1000，时间戳为13位的话不需乘1000
    var year = date.getFullYear()
    var month = String(date.getMonth() + 1).padStart(2, 0)
    var dateT = String(date.getDate()).padStart(2, 0)
    var hour = String(date.getHours()).padStart(2, 0)
    var minute = String(date.getMinutes()).padStart(2, 0)
    var second = String(date.getSeconds()).padStart(2, 0)
    return year + '-' + month + '-' + dateT + ' ' + hour + ':' + minute + ':' + second
}
/**
 * @summary 时间格式化
 * @param {*} time 
 * @param {*} format 
 */
export function formatDate(time, format = ' - ') {
    if (!time) return ''
    if (typeof time === 'number') {
        // 时间戳转YYYY-MM
        time = time.toString()
    }
    time = time.trim() // 清除前后空格
    const Reg = /^(\d{4})[-|/|年]([0][1-9]|[1][0-2])[-|/|月]([1-9]|[012]\d|3[01])\s*(\d{0,2}):(\d{0,2}):(\d{0,2})$/gi
    var timeArray = Reg.exec(time)
    var year, month, day
    year = timeArray[1]// 年
    month = timeArray[2]// 月
    day = timeArray[3]// 日
    if (Array.isArray(format)) {
        switch (format.length) {
            case 0:
                return year + ' / ' + month + ' / ' + day
            case 1:
                return year + format[0] + month + ' / ' + day;
            case 2:
                return year + format[0] + month + format[1] + day;
            case 3:
                return year + format[0] + month + format[1] + day + format[2]
            default:
                return year + format[0] + month + format[1] + day + format.slice(2).join(" ")
        }
    }
    return year + format + month + format + day
}
/**
 * @summary 深拷贝
 * @param {*} obj 拷贝对象
 * @param {*} weakMap 缓存
 */
export function deepCopy(obj, weakMap = new WeakMap()) {
    if (weakMap.has(obj)) { return weakMap.get(obj) }
    if (obj === null) { return null }
    if (obj instanceof RegExp) { return new RegExp(obj) }
    if (obj instanceof Date) { return new Date(obj) }
    if (typeof obj !== 'object') { return obj }
    const ObjType = obj.constructor()
    // 处理Symbol情况
    let symbolType = Object.getOwnPropertySymbols(obj)
    if (symbolType.length) {
        symbolType.forEach(item => {
            if (typeof obj[item] == 'object' && obj[item] != null) {
                ObjType[item] = deepCopy(obj[item])
            } else {
                ObjType[item] = obj[item]
            }
        })
    }
    weakMap.set(obj, ObjType)
    for (const key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
            ObjType[key] = deepCopy(obj[key], weakMap)
        }
    }
    return ObjType
}
/**
 * @summary 对象数据去重
 * @param {*} arr 数据源
 * @param {*} uniqueFlag 属性
 */
export function uniqueArrObj(arr, uniqueFlag) {
    const tempArr = []
    const uniqueVal = []
    for (const item of arr) {
        if (uniqueVal.includes(item[uniqueFlag])) continue
        uniqueVal.push(item[uniqueFlag])
        tempArr.push(item)
    }
    return tempArr
}
/**
 * @summary 数组拆分
 * @param {*} arr 
 * @param {*} size 把size个数拆分为一个数组
 */
export function arrSplit(arr = [], size = 1) {
    if (Object.prototype.toString.call(arr).slice(8, -1) == 'Array') {
        return arr.length ? arr.reduce((prv, cur) => (prv[prv.length - 1].length === size ? prv.push([cur]) : prv[prv.length - 1].push(cur), prv), [[]]) : []
    }
    let msg = "the data source isn't an array!"
    throw new Error(msg.toUpperCase())
}

/**
 * @summary 防抖
 * @param {*} func 需要执行的函数
 * @param {*} wait 等待时间
 * @param {*} immediate 是否立即执行
 */
export function debounce(func, wait = 3000) {
    var timeout;
    const debounceInnerFn = function () {
        if (timeout) clearTimeout(timeout);
        timeout = setTimeout(() => {
            func.call(this, arguments)
        }, wait);
    }
    debounceInnerFn.cancel = function () {
        clearTimeout(timeout);
        timeout = null
    }
    return debounceInnerFn
}
/**
 * @summary 千分符参数
 * @param {*} num 数据源
 */
export function thousands(num) {
    if (typeof num === 'string' || typeof num === 'number') {
        return (num.toString().indexOf('.') !== -1) ? Number(num).toLocaleString() : num.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
    }
    return num
}
/**
 * @summary 路径参数解析
 * @param {*} url 解析路径
 */
export function getQueryObject(url) {
    url = url ? window.location.href : url
    var search = url.substring(url.lastIndexOf('?') + 1)
    var obj = {}
    var reg = /([^?&=]+)=([^?&=]*)/g
    search.replace(reg, function (rs, $1, $2) {
        var name = decodeURIComponent($1)
        var val = decodeURIComponent($2)
        val = String(val)
        obj[name] = val
        return rs
    })
    return obj
}
/**
 * @summary 根据数据下载文件
 * @param {*} name 文件下载名称
 * @param {*} data 数据源
 * @param {*} type 数据下载类型
 */
export function downloadData(name, data, type) {
    const element = document.createElementNS('http://www.w3.org/1999/xhtml', 'a')
    const ev = document.createEvent('MouseEvents')
    const urlObject = window.URL || window.webkitURL || window
    const export_blob = new Blob([data], { type: type || '' })
    element.href = urlObject.createObjectURL(export_blob)
    element.download = name
    ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
    element.dispatchEvent(ev)
    urlObject.revokeObjectURL(element.href) // 释放实例
    element.href = ''
}
/**
 * @summary 根据url地址下载文件
 * @param {*} url  文件地址
 */
export function downloadUrl(url) {
    let isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
    let isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
    if (isChrome || isSafari) {
        let link = document.createElement('a');
        link.href = url;
        if (link.download !== undefined) {
            let fileName = url.substring(url.lastIndexOf('/') + 1, url.length);
            link.download = fileName;
        }
        if (document.createEvent) {
            let e = document.createEvent('MouseEvents');
            e.initEvent('click', true, true);
            link.dispatchEvent(e);
            return true;
        }
    }
    if (url.indexOf('?') === -1) {
        url += '?download';
    }
    window.open(url, '_self');
    return true;
}

/**
 * @summary 树型数据遍历
 * @param {*} tree  树形结构数据
 * @param {*} fn 执行函数
 */
export function treeForeach(fn, tree = []) {
    tree.forEach(item => {
        item.children && treeForeach(item.children, fn)
        fn(item)
    })
}
/**
 * @summary 列表数据转树型结构
 * @param {*} id 对象属性ID
 * @param {*} parentId 对象属性对应的父级ID
 * @param {*} list 数据源
 */
export function listToTree(list = [], id = null, parentId = null) {
    let info = list.reduce((t, v) => (t[v[id]] = v, v.children = [], t), {})
    return list.filter(node => {
        info[node[parentId]] && info[node[parentId]].children.push(node)
        return !node[parentId]
    })
}
/**
 * @summary 树形数据转列表
 * @param {*} tree 
 * @param {*} result 
 * @param {*} level 
 */
export function treeToList(tree = [], result = [], level = 0, isRecursion = true, ) {
    /**
     *递归模式
     */
    if (isRecursion) {
        tree.forEach(node => {
            result.push(node)
            node.level = level + 1
            node.children && treeToList(node.children, result, level + 1)
        })
        return result
    }
    /**
     * 循环模式
     */
    let res = tree.map(node => (node.level = 1, node))
    for (let i = 0; i < res.length; i++) {
        if (!res[i].children) continue
        let list = res[i].children.map(node => (node.level = res[i].level + 1, node))
        res.splice(i + 1, 0, ...list)
    }
    return res
}
/**
 * @summary 筛选
 * @param {*} tree 数据源
 * @param {*} fn 执行函数
 */
export function treeFilter(fn, tree = []) {
    return tree.map(node => ({ ...node })).filter(node => {
        node.children = node.children && treeFilter(node.children, fn)
        return fn(node) || (node.children && node.children.length)
    })
}
/**
 * @summary 查找树节点
 * @param {*} tree 
 * @param {*} fn 
 */
export function treeFind(fn, tree = []) {
    for (let item of tree) {
        if (fn(item)) return item
        if (item.children) {
            return treeFind(item.children, fn) || []
        }
    }
    return []
}
/**
 * @summary 数组扁平化
 * @param {*} arr 
 */
export function Flat(arr = []) {
    return arr.reduce((prv, cur) => prv.concat(Array.isArray(cur) ? cur.flat() : cur), [])
}
/**
 * @summary 对字符串进行加密
 * @param {*} code 
 */
export function compileStr(code) {
    var c = String.fromCharCode(code.charCodeAt(0) + code.length)
    for (var i = 1; i < code.length; i++) {
        c += String.fromCharCode(code.charCodeAt(i) + code.charCodeAt(i - 1))
    }
    return escape(c)
}
/**
 * @summary 字符串进行解密
 * @param {*} code 
 */
export function unCompileStr(code) {
    code = unescape(code)
    var c = String.fromCharCode(code.charCodeAt(0) - code.length)
    for (var i = 1; i < code.length; i++) {
        c += String.fromCharCode(code.charCodeAt(i) - c.charCodeAt(i - 1))
    }
    return c
}

/**
 * @summary 内容复制
 * @param {*} txt 
 */
export function copyToClipboard(txt) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        clipboardData.setData("Text", txt);
        console.log("复制成功！");
    } else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = txt;
    } else if (window.netscape) {
        let componentsInterfaces = Components.interfaces
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            throw new Error("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");
        }
        let clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(componentsInterfaces.nsIClipboard);
        if (!clip)
            return;
        let trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(componentsInterfaces.nsITransferable);
        if (!trans)
            return;
        trans.addDataFlavor("text/unicode");
        let str = Components.classes["@mozilla.org/supports-string;1"].createInstance(componentsInterfaces.nsISupportsString);
        let copyText = txt;
        str.data = copyText;
        trans.setTransferData("text/unicode", str, copyText.length * 2);
        let clipId = componentsInterfaces.nsIClipboard;
        if (!clip)
            return false;
        clip.setData(trans, null, clipId.kGlobalClipboard);
        console.log("复制成功！");
    }
}

/**
 * @summary 校验数据类型
 * @param {*} obj 数据对象
 * @param {*} typeName 类型
 */
export const isNull = (obj, typeName) => {
    return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === typeName.toLowerCase()
}

/**
 * @summary 是否是微信浏览器
 */
export const isWeiXin = () => {
    return ua.match(/microMessenger/i) == 'micromessenger'
}
/**
 * @summary 是否是移动端
 */
export const isDeviceMobile = () => {
    const ua = navigator.userAgent
    return /android|webos|iphone|ipod|balckberry/i.test(ua)
}
/**
 * @summary 检查当前设备
 */
export const deviceMobileType = () => {
    var u = navigator.userAgent;
    if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {  //安卓手机
        return 'Android'
    } else if (u.indexOf('iPhone') > -1) {//苹果手机
        return 'iPhone'
    } else if (u.indexOf('iPad') > -1) {//iPad
        return 'ipad'
    } else if (u.indexOf('Windows Phone') > -1) {//winphone手机
        return 'windowsPhone'
    } else if (u.indexOf('SymbianOS')) {
        return 'SymbianOS'
    } else {
        return 'PC'
    }
}
/**
 * @summary 去除html标签
 * @param {*} str html元素
 */
export const removehtmltag = (str) => {
    return str.replace(/<[^>]+>/g, '')
}
/**
 * @summary el是否包含某个class
 * @param {*} el  元素目标
 * @param {*} className 样式类名称
 */
export const hasClass = (el, className) => {
    let reg = new RegExp('(^|\\s)' + className + '(\\s|$)')
    return reg.test(el.className)
}
/**
 * @summary el添加某个class
 * @param {*} el 
 * @param {*} className 
 */
export const addClass = (el, className) => {
    if (hasClass(el, className)) {
        return
    }
    let newClass = el.className.split(' ')
    newClass.push(className)
    el.className = newClass.join(' ')
}
/**
 * @summary el去除某个class
 * @param {*} el 
 * @param {*} className 
 */
export const removeClass = (el, className) => {
    if (!hasClass(el, className)) {
        return
    }
    let reg = new RegExp('(^|\\s)' + className + '(\\s|$)', 'g')
    el.className = el.className.replace(reg, ' ')
}
/**
 * @summary 滚动到顶部
 */
export const scrollToTop = () => {
    const c = document.documentElement.scrollTop || document.body.scrollTop;
    if (c > 0) {
        window.requestAnimationFrame(scrollToTop);
        window.scrollTo(0, c - c / 8);
    }
}

/**
 * @summary el是否在视口范围内
 * @param {*} el 
 * @param {*} partiallyVisible 
 */
export const elementIsVisibleInViewport = (el, partiallyVisible = false) => {
    const { top, left, bottom, right } = el.getBoundingClientRect();
    const { innerHeight, innerWidth } = window;
    return partiallyVisible
        ? ((top > 0 && top < innerHeight) || (bottom > 0 && bottom < innerHeight)) &&
        ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
        : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
}

/**
 * 
 * @param {*} str 校验数据源
 * @param {*} type 类型 phone(手机) tel(座机) card(身份证) pwd(字母开头，长度在6~18之间密码) postal(邮政编码) email(邮箱)
 */
export const checkStr = (str, type) => {
    switch (type) {
        case 'phone':   //手机号码
            return /^1[3|4|5|6|7|8|9][0-9]{9}$/.test(str);
        case 'tel':     //座机
            return /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/.test(str);
        case 'card':    //身份证
            return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(str);
        case 'pwd':     //密码以字母开头，长度在6~18之间，只能包含字母、数字和下划线
            return /^[a-zA-Z]\w{5,17}$/.test(str)
        case 'postal':  //邮政编码
            return /[1-9]\d{5}(?!\d)/.test(str);
        case 'QQ':      //QQ号
            return /^[1-9][0-9]{4,9}$/.test(str);
        case 'email':   //邮箱
            return /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(str);
        case 'money':   //金额(小数点2位)
            return /^\d*(?:\.\d{0,2})?$/.test(str);
        case 'URL':     //网址
            return /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(str)
        case 'IP':      //IP
            return /((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))/.test(str);
        case 'date':    //日期时间
            return /^(\d{4})\-(\d{2})\-(\d{2}) (\d{2})(?:\:\d{2}|:(\d{2}):(\d{2}))$/.test(str) || /^(\d{4})\-(\d{2})\-(\d{2})$/.test(str)
        case 'number':  //数字
            return /^[0-9]$/.test(str);
        case 'english': //英文
            return /^[a-zA-Z]+$/.test(str);
        case 'chinese': //中文
            return /^[\\u4E00-\\u9FA5]+$/.test(str);
        case 'lower':   //小写
            return /^[a-z]+$/.test(str);
        case 'upper':   //大写
            return /^[A-Z]+$/.test(str);
        case 'HTML':    //HTML标记
            return /<("[^"]*"|'[^']*'|[^'">])*>/.test(str);
        default:
            return true;
    }
}
/**
 * @summary 随机数范围
 * @param {*} min 最小数
 * @param {*} max 最大数
 */
export let random = (min, max) => {
    let params = Array.from(arguments)
    if (params.length === 2) {
        return Math.floor(Math.random() * ((max + min) - min))
    } else {
        return Math.random();
    }
}
/**
 * @summary 将数字转换为大写金额
 * @param {*} Num 金额
 */
export const changeToChinese = (Num) => {
    //判断如果传递进来的不是字符的话转换为字符
    if (typeof Num == "number") {
        Num = new String(Num);
    };
    Num = Num.replace(/,/g, "") //替换tomoney()中的“,”
    Num = Num.replace(/ /g, "") //替换tomoney()中的空格
    Num = Num.replace(/￥/g, "") //替换掉可能出现的￥字符
    if (isNaN(Num)) { //验证输入的字符是否为数字
        //alert("请检查小写金额是否正确");
        return "";
    };
    //字符处理完毕后开始转换，采用前后两部分分别转换
    var part = String(Num).split(".");
    var newchar = "";
    //小数点前进行转化
    for (var i = part[0].length - 1; i >= 0; i--) {
        if (part[0].length > 10) {
            return alert('您输入的数字过于太大，请确认后重新提交！');
            //若数量超过拾亿单位，提示
        }
        var tmpnewchar = ""
        var perchar = part[0].charAt(i);
        switch (perchar) {
            case "0":
                tmpnewchar = "零" + tmpnewchar;
                break;
            case "1":
                tmpnewchar = "壹" + tmpnewchar;
                break;
            case "2":
                tmpnewchar = "贰" + tmpnewchar;
                break;
            case "3":
                tmpnewchar = "叁" + tmpnewchar;
                break;
            case "4":
                tmpnewchar = "肆" + tmpnewchar;
                break;
            case "5":
                tmpnewchar = "伍" + tmpnewchar;
                break;
            case "6":
                tmpnewchar = "陆" + tmpnewchar;
                break;
            case "7":
                tmpnewchar = "柒" + tmpnewchar;
                break;
            case "8":
                tmpnewchar = "捌" + tmpnewchar;
                break;
            case "9":
                tmpnewchar = "玖" + tmpnewchar;
                break;
        }
        switch (part[0].length - i - 1) {
            case 0:
                tmpnewchar = tmpnewchar + "元";
                break;
            case 1:
                if (perchar != 0) tmpnewchar = tmpnewchar + "拾";
                break;
            case 2:
                if (perchar != 0) tmpnewchar = tmpnewchar + "佰";
                break;
            case 3:
                if (perchar != 0) tmpnewchar = tmpnewchar + "仟";
                break;
            case 4:
                tmpnewchar = tmpnewchar + "万";
                break;
            case 5:
                if (perchar != 0) tmpnewchar = tmpnewchar + "拾";
                break;
            case 6:
                if (perchar != 0) tmpnewchar = tmpnewchar + "佰";
                break;
            case 7:
                if (perchar != 0) tmpnewchar = tmpnewchar + "仟";
                break;
            case 8:
                tmpnewchar = tmpnewchar + "亿";
                break;
            case 9:
                tmpnewchar = tmpnewchar + "拾";
                break;
        }
        var newchar = tmpnewchar + newchar;
    }
    //小数点之后进行转化
    if (Num.indexOf(".") != -1) {
        if (part[1].length > 2) {
            // alert("小数点之后只能保留两位,系统将自动截断");
            part[1] = part[1].substr(0, 2)
        }
        for (i = 0; i < part[1].length; i++) {
            tmpnewchar = ""
            perchar = part[1].charAt(i)
            switch (perchar) {
                case "0":
                    tmpnewchar = "零" + tmpnewchar;
                    break;
                case "1":
                    tmpnewchar = "壹" + tmpnewchar;
                    break;
                case "2":
                    tmpnewchar = "贰" + tmpnewchar;
                    break;
                case "3":
                    tmpnewchar = "叁" + tmpnewchar;
                    break;
                case "4":
                    tmpnewchar = "肆" + tmpnewchar;
                    break;
                case "5":
                    tmpnewchar = "伍" + tmpnewchar;
                    break;
                case "6":
                    tmpnewchar = "陆" + tmpnewchar;
                    break;
                case "7":
                    tmpnewchar = "柒" + tmpnewchar;
                    break;
                case "8":
                    tmpnewchar = "捌" + tmpnewchar;
                    break;
                case "9":
                    tmpnewchar = "玖" + tmpnewchar;
                    break;
            }
            if (i == 0) tmpnewchar = tmpnewchar + "角";
            if (i == 1) tmpnewchar = tmpnewchar + "分";
            newchar = newchar + tmpnewchar;
        }
    }
    //替换所有无用汉字
    while (newchar.search("零零") != -1)
        newchar = newchar.replace("零零", "零");
    newchar = newchar.replace("零亿", "亿");
    newchar = newchar.replace("亿万", "亿");
    newchar = newchar.replace("零万", "万");
    newchar = newchar.replace("零元", "元");
    newchar = newchar.replace("零角", "");
    newchar = newchar.replace("零分", "");
    if (newchar.charAt(newchar.length - 1) == "元") {
        newchar = newchar + "整"
    }
    return newchar.trim();
}
/**
 * @summary 删除元素
 * @param {*} arr 数组源
 * @param {*} ele 需要删除的元素
 *  @param {*} deleteNum 删除数量
 */
export const remove = (arr, ele, deleteNum = 1) => {
    var index = arr.indexOf(ele);
    if (index > -1 && deleteNum <= arr.length) {
        arr.splice(index, deleteNum);
    }
    return arr;
}

/**
 * @summary 去除空格
 * @param {*} str 数据源
 * @param {*} type 类型 1-所有空格 2-前后空格 3-前空格 4-后空格
 */
export const trim = (str, type) => {
    type = type || 1
    switch (type) {
        case 1:
            return str.replace(/\s+/g, "");
        case 2:
            return str.replace(/(^\s*)|(\s*$)/g, "");
        case 3:
            return str.replace(/(^\s*)/g, "");
        case 4:
            return str.replace(/(\s*$)/g, "");
        default:
            return str;
    }
}

/**
 * @summary 字符转换
 * @param {*} str 数据源
 * @param {*} type 类型 1:首字母大写 2：首字母小写 3：大小写转换 4：全部大写 5：全部小写
 */
export const changeCase = (str, type) => {
    type = type || 4
    switch (type) {
        case 1:
            return str.replace(/\b\w+\b/g, function (word) {
                return word.substring(0, 1).toUpperCase() + word.substring(1).toLowerCase();

            });
        case 2:
            return str.replace(/\b\w+\b/g, function (word) {
                return word.substring(0, 1).toLowerCase() + word.substring(1).toUpperCase();
            });
        case 3:
            return str.split('').map(function (word) {
                if (/[a-z]/.test(word)) {
                    return word.toUpperCase();
                } else {
                    return word.toLowerCase()
                }
            }).join('')
        case 4:
            return str.toUpperCase();
        case 5:
            return str.toLowerCase();
        default:
            return str;
    }
}

/**
 * @summary 特殊符号转换
 * @param {*} str 需要转译的字符串
 */
export function escapeHtml(str) {
    return str.replace(/[<>"&]/g, function (match) {
        switch (match) {
            case '<':
                return '&lt;';
            case '>':
                return '&gt;';
            case '&':
                return '&amp;';
            case '\"':
            case '\'':
                return '&quot;';
            default:
                return ''
        }
    });
}